package cn.net.yugu.doraemon.netty.processor;

/**
 * @description:
 * @author: wanghongli
 * @create: 2022-07-12 14:08:34
 */
public class MessageProcessorNotice {
    public interface Notice {
        void notice(String info);
    }

    public interface MessageFilter {
        boolean processMessageBefore(Notice busyNotice, Object message, long submitTime, long beginTime);
    }

    private final MessageFilter messageFilter;
    private final Notice busyNotice;
    private final Notice errorNotice;

    public MessageProcessorNotice(MessageFilter messageFilter, Notice busyNotice, Notice errorNotice) {
        this.messageFilter = messageFilter;
        this.busyNotice = busyNotice;
        this.errorNotice = errorNotice;
    }

    public MessageProcessorNotice(Notice busyNotice, Notice errorNotice) {
        this.messageFilter = null;
        this.busyNotice = busyNotice;
        this.errorNotice = errorNotice;
    }

    public MessageProcessorNotice(Notice errorNotice) {
        this.messageFilter = null;
        this.busyNotice = null;
        this.errorNotice = errorNotice;
    }

    public boolean processMessageBefore(Object message, long submitTime, long beginTime) {
        if (messageFilter == null) {
            return true;
        }
        return messageFilter.processMessageBefore(busyNotice, message, submitTime, beginTime);
    }

    public void errorNotice(String info) {
        if (errorNotice != null) {
            errorNotice.notice(info);
        }
    }

}
